
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* SUMMARY STATISTICS: RESIDENTS
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

cd "$mypathRR/Results/Resident/summary_stats"

preserve
sort persid year

egen woaexp = rowtotal(z220s1  z221s1  z222s1  z223s1)
replace woaexp = round(woaexp)
label var woaexp "Expenses related to weekend residency"

egen profexp = rowtotal(z255s1  z256s1)
replace profexp = round(profexp)
label var profexp "Professional expenses"

gen total=0
label def total 0 "Total", modify
label val total total

gen rest=(taxinc_thre2!=1 & ctrl_ir_60_80 !=1)
label def rest 1 "Non-treated"

gen avgt_wtax1 = avgt_stverm_taxable * 100 if year<2006 
gen avgt_wtax2 = avgt_stverm_taxable * 100 if year>2005 & year<2008 
	label var avgt_wtax1 	"Avg. wealth tax $(t<2006)$ "
	label var avgt_wtax2 	"Avg. wealth tax $(t \geq 2006^*)$ "

label var sex "Female"
label var age "Age"
label var married "Married"
label var doppel "Double earners"
label var snpanzki "Nr. dependents"
label var employee "Employee"
label var self_emp "Self employed"
label var farmer "Farmer"
label var retiree "Retiree"
label var labor_ratio "Share of income from emplyoment"
label var self_ratio "Share of income from self-employment"
label var cap_ratio "Share of capital income"
label var inmob_ratio "Share of inmobile income"
label var mob_ratio "Share of mobile income"
label var labor_index3 "Major income source: employment"
label var self_index3 "Major income source: self-employment"
label var mob_index3 "Major income source: mobile income"
label var cap_index3 "Major income source: capital income"
label var mob_inc "Real mobile income (1000 CHF)"
label var labor_inc "Real income from employment (1000 CHF)"
label var self_inc "Real income from self-employment (1000 CHF)"
label var esatzbestkopf "Real rate-determining income (1000 CHF)"
label var esteuerbst "Real taxable income (1000 CHF)"
label var vsatzbestkopf "Real rate-determining wealth (10K CHF)"
label var vsteuerbst "Real taxable wealth in (10K CHF)"
label var woaufenthalt "Weekend residents"
label var swiss "Swiss citizen"
label var zuzugausland "Moved-in from abroad"
label var pauschaliert "Expenditure-based taxation"

replace kirche= kirche-1
label var kirche "Protestant"

foreach var in mob_inc labor_inc self_inc esatzbestkopf esteuerbst {
replace `var' = `var'/1000
replace `var' = round(`var')
recast int `var'
}

foreach var in vsatzbestkopf vsteuerbst {
replace `var' = `var'/10000
replace `var' = round(`var')
recast int `var'
}

replace avg_ntr1=avg_ntr1 * 100  
	label var avg_ntr1 	"Avg. NTR $(t<2006)$"
replace avg_ntr2=avg_ntr2 * 100 
	label var avg_ntr2 "Avg. NTR $(t\geq 2006^*)$"

           
replace mtr_total = mtr_total*100
    label var mtr_total "Total marginal tax rate"

eststo clear

* tax burden
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize ///
avg_ntr1 avg_ntr2 avgt_wtax1 avgt_wtax2 /* total */  ///
  if `group'==1
  eststo, prefix(eresi)
  
  estwrite . using est_`group'_resi, replace
  }


* hh characteristics  
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize  ///
sex age married doppel snpanzki kirche swiss zuzugausland pauschaliert woaufenthalt  /* woaexp profexp */ ///
  if `group'==1
  eststo, prefix(eresi)
  
  estwrite . using est_`group'_resi, append
  }

* employment
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize ///
employee self_emp  retiree ///
  if `group'==1
  eststo, prefix(eresi)


  estwrite . using est_`group'_resi, append
  }

* share income from  
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize  /// 
  labor_ratio self_ratio cap_ratio transfer_ratio /*mob_ratio*/ ///
  if `group'==1
  eststo, prefix(eresi)
  
  estwrite . using est_`group'_resi, append
  }
 
* Income (rate determining vs. taxable)
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize  /// 
  esatzbestkopf esteuerbst    ///
  if `group'==1
  eststo, prefix(eresi)

  estwrite . using est_`group'_resi, append
}
  
* wealth (rate determining vs. taxable)
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize  /// 
   vsatzbestkopf  vsteuerbst   ///
  if `group'==1
  eststo, prefix(eresi)
  
  estwrite . using est_`group'_resi, append
}
 
* tax savings: non existent for residents
replace taxsavings = 0
replace meantaxsavings = 0
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize  /// 
  taxsavings meantaxsavings ///
  if `group'==1
  eststo, prefix(eresi)

  estwrite . using est_`group'_resi, append
}

* driving distance: non existent for residents
replace dist_km = 0
replace dist_min = 0 
foreach group in  taxinc_thre2  ctrl_ir_60_80  rest     {
quietly estpost summarize  /// 
  dist_km dist_min  ///
  if `group'==1
  eststo, prefix(eresi)

  estwrite . using est_`group'_resi, append
}


* N
estpost tab taxinc_thre2 if taxinc_thre2 == 1 
estpost tab ctrl_ir_60_80 if ctrl_ir_60_80 == 1 
estpost tab rest if rest == 1 

restore
